﻿using ModelEntities.Adapter;
using ModelEntities.Tracabilite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ReprisePV.UserControls
{
    /// <summary>
    /// Logique d'interaction pour DataGridTracabilite.xaml
    /// </summary>
    public partial class DataGridTracabilite : UserControl
    {
        #region PV de la grille

        public MEntetePV PV
        {
            get { return (MEntetePV)GetValue(PVProperty); }
            set { SetValue(PVProperty, value); }
        }

        // Using a DependencyProperty as the backing store for PV.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PVProperty =
            DependencyProperty.Register("PV", typeof(MEntetePV), typeof(DataGridTracabilite), new PropertyMetadata(new MEntetePV(), PVChanged));

        private static void PVChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataGridTracabilite grid = d as DataGridTracabilite;
            if (grid != null)
            {
                DataGridTracabiliteVM vm = grid.Resources["vmDG"] as DataGridTracabiliteVM;
                vm.PVActuel = (e.NewValue as MEntetePV);
            }
        }

        #endregion

        public DataGridTracabilite()
        {
            InitializeComponent();
        }

        public Traçabilites DataSource
        {
            get
            {
                DataGridTracabiliteVM vm = this.Resources["vmDG"] as DataGridTracabiliteVM;
                return vm.Traca;
            }
        }

        private void CollectionViewSourceTR_Filter(object sender, FilterEventArgs e)
        {
            DataGridTracabiliteVM vm = this.Resources["vmDG"] as DataGridTracabiliteVM;
            if (vm != null)
            {
                ModelEntities.Tracabilite.Traçabilite item = e.Item as ModelEntities.Tracabilite.Traçabilite;
                if (item != null)
                {
                    e.Accepted = (item.NoPage == vm.PageActuel);
                }
            }
        }
    }
}
